package com.lg.aptcomp.utils

import android.graphics.Color
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import com.google.android.material.textfield.TextInputLayout
import com.lg.aptcomp.R

class BindingAdapterUtils {
    companion object {

        @JvmStatic
        @BindingAdapter("hintWithAsterisk")
        fun setHintWithAsterisk(view: TextInputLayout, hint: String?) {
            val textSpannable = SpannableString("$hint*")
            textSpannable.setSpan(ForegroundColorSpan(ContextCompat.getColor(view.context!!, R.color.text_color_secondary)), 0, textSpannable.length - 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
            textSpannable.setSpan(ForegroundColorSpan(Color.RED), textSpannable.length - 1, textSpannable.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
            view.hint = textSpannable
        }
    }
}